#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct cointype
{
	double value;
	double weight;
	double rate;
};

double		minvalue;
struct cointype	coin[501];
double		maxweight;
long		n;
long		Ncase;


int search(int x,double currcost,double restw)
{
	long i,maxnum;
	if (restw==0) 
	{
		minvalue=currcost;
		return 0;
	}
	if (x>n) return 0;
	if (currcost+restw*coin[x].rate>minvalue) return 0;
	maxnum=long(restw/coin[x].weight);
	currcost+=coin[x].value*long(restw/coin[x].weight);
	restw-=coin[x].weight*long(restw/coin[x].weight);
	for (i=maxnum;i>=0;i--)
	{
		search(x+1,currcost,restw);
		currcost-=coin[x].value;
		restw+=coin[x].weight;
	}
	return 0;
}

int qsort(int st,int ed)
{
	struct	cointype x;
	int		i,j;
	if (st>=ed) return 0;
	x=coin[st];
	i=st; j=ed;
	while (i<j)
	{
		while (i<j && coin[j].rate>=x.rate) j--;
		coin[i]=coin[j];
		while (i<j && coin[i].rate<=x.rate) i++;
		coin[j]=coin[i];
	}
	coin[i]=x;
	qsort(st,i-1);
	qsort(i+1,ed);
	return 0;
}

main()
{
	long	ct,a,b,i;
	scanf("%ld",&Ncase);
	for (ct=1;ct<=Ncase;ct++)
	{
		scanf("%ld%ld",&a,&b);
		scanf("%ld",&n);
		for (i=1;i<=n;i++)
		{
			scanf("%lf%lf",&(coin[i].value),&(coin[i].weight));
			coin[i].rate=coin[i].value/coin[i].weight;
		}
		qsort(1,n);
		maxweight=b-a;
		minvalue=1e11;
		search(1,0,maxweight);
		if (minvalue<1e10) 
			printf("The minimum amount of money in the piggy-bank is %0.0lf.\n",minvalue);
		else 
			printf("This is impossible.\n");
	}
	return 0;
}